package com.sunday.fangdaifu.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sunday.fangdaifu.R;
import com.sunday.fangdaifu.activity.task.HistoryTaskDetailActivity;
import com.sunday.fangdaifu.model.HistoryTaskList;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by yun_sheng on 2017/6/29.
 */

public class HistoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List<HistoryTaskList> dataSet;
    private View.OnClickListener onClickListener;


    public HistoryAdapter(Context context) {
        mContext = context;

    }

    public void setData(List<HistoryTaskList> datas) {
        dataSet = datas;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_history, parent, false);
        return new ItemViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final HistoryTaskList historyTaskList = dataSet.get(position);
        ItemViewHolder viewHolder = (ItemViewHolder) holder;
        viewHolder.problem.setText(historyTaskList.getCount()+"个问题");
        viewHolder.time.setText(historyTaskList.getRemark());
        viewHolder.item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(mContext, HistoryTaskDetailActivity.class);
                intent.putExtra("historyTaskList", historyTaskList);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return dataSet == null ? 0 : dataSet.size();
    }

    public void setOnClickListener(View.OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public class ItemViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.time)
        TextView time;
        @Bind(R.id.problem)
        TextView problem;
        @Bind(R.id.item)
        RelativeLayout item;

        public ItemViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
